package com.lc.demo.service.impl;

import com.lc.demo.bean.Leavetable;
import com.lc.demo.bean.Signin;
import com.lc.demo.mapper.LeaveMapper;
import com.lc.demo.mapper.SigninMapper;
import com.lc.demo.service.LeavetableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LeavetableServiceImpl implements LeavetableService {

    @Autowired
    private LeaveMapper leaveMapper;

    @Autowired
    private SigninMapper signinMapper;


    @Override
    public List<Leavetable> findLeaveList(Leavetable leavetable) {
        leavetable.setState(0);
        return leaveMapper.select(leavetable);
    }

    @Override
    public void reviewLeave(Leavetable leavetable) {
        //更新签到表
        if (leavetable.getState()==1){
            Signin signin = new Signin();
            signin.setCourseid(leavetable.getCourseid());
            signin.setWeekday(leavetable.getWeekday());
            signin.setDaytime(leavetable.getDaytime());
            signin.setStudentid(leavetable.getStudentid());
            List<Signin> select = signinMapper.select(signin);
            Signin signin1 = select.get(0);
            //状态设置为2 已请假
            signin1.setState(2);
            signinMapper.updateByPrimaryKeySelective(signin1);
        }
        leaveMapper.updateByPrimaryKeySelective(leavetable);
    }
}
